<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>权限框架</title>
    <link rel="stylesheet" type="text/css" href="/css/style.css">
    <!--[if lt IE 9]>
    <script src="/js/html5.js"></script>

    <![endif]-->
    <script src="/js/jquery.js"></script>

    <script src="/js/jquery.mCustomScrollbar.concat.min.js"></script>

    <script>
        $(function () {
            var tmp = /([a-zA-Z0-9]{1,18})/;
            $("#userCode").focus(function () {
                if ($(this).val() === '请输入用户编码')
                    $(this).val("");
                $(this).css("color", "#333333");
            }).blur(function () {
                if ($(this).val() === "") {
                    $("#userCodeInfo").html("用户编码不能为空");
                } else if ($(this).val() !== "") {
                    if (!tmp.test($(this).val())) {
                        $("#userCodeInfo").html("用户编码不合法");
                    }else{
                        $("#userCodeInfo").html("");
                    }
                }

            });


            $("#userName").focus(function () {
                if ($(this).val() === '请输入用户名')
                    $(this).val("");
            }).blur(function () {
                if ($(this).val() === "") {
                    $("#userNameInfo").html("用户名不能为空");
                } else if ($(this).val() !== "") {
                    // if ($("#contents").html() ==="用户名不能为空"){
                    $("#userNameInfo").html("");
                    // }
                }
            });
            //注册手机号
            $("#phone").focus(function () {
                if ($(this).val() === '请输入手机号')
                    $(this).val("");
                $(this).css("color", "#333333");
            }).blur(function () {
                if ($(this).val() === "") {
                    $("#userPhoneInfo").html("请输入手机号");
                } else if ($(this).val() !== "") {
                    if (!$(this).val().match(/(^1[0-9]{10}$)/)) {
                        $("#userPhoneInfo").html("手机号格式不正确");
                    } else if ($(this).val() !== "") {
                        $("#userPhoneInfo").html("");

                    }
                }
            });

            $("#userPassword").focus(function () {
                if ($(this).val() === '请输入手机号')
                    $(this).val("");
                $(this).css("color", "#333333");
            }).blur(function () {
                if ($(this).val() === "") {
                    $("#userPasswordInfo").html("请输入新密码");
                } else if ($(this).val() !== "") {
                    if (!$(this).val().match(/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,16}$/)) {
                        $("#userPasswordInfo").html("密码格式不正确");
                    } else if ($(this).val() !== "") {
                        $("#userPasswordInfo").html("");

                    }
                }
            });

        })
    </script>
    <script>
        function check () {
            var userCodeInfo =$("#userCodeInfo").html();
            var userNameInfo=$("#userNameInfo").html();
            var phoneInfo=$("#userPhoneInfo").html();
            var userPasswordInfo=$("#userPasswordInfo").html();
            if (userCodeInfo!=="" || userNameInfo !=="" || phoneInfo!==""||userPasswordInfo!==""){
                alert("添加失败！请检查用户信息")
                return false;
            }else{
                return true;
            }
        }
    </script>

</head>
<body>
<div th:replace="head::header"></div>
<div class="rt_content">

    <div class="page_title">
        <h2 class="fl">修改会员信息</h2>
    </div>
    <div class="providerAdd">
        <form th:action="@{/user/user_update(id=${user.id})}" method="post" onsubmit="return check();">
            <div class="form-group">
                <label>用户编码：</label>
                <a style="color: red">*</a>
                <input class="form-control" th:value="${user.userCode}" name="userCode" id="userCode"><span style="color: red" id="userCodeInfo"></span>
            </div>
            <div class="form-group">
                <label>用户名称：</label>
                <a style="color: red">*</a>
                <input  class="form-control" th:value="${user.userName}" name="userName" id="userName"><span style="color: red" id="userNameInfo"></span>
            </div>
            <div class="form-group">
                <label>密码：</label>
                <a style="color: red">*</a>
                <input class="form-control" type="password"  th:value="${user.userPassword}" name="userPassword" id="userPassword"><span style="color: red" id="userPasswordInfo"></span>
            </div>
            <div class="form-group">
                <label>电话：</label>
                <a style="color: red">*</a>
                <input  class="form-control" th:value="${user.phone}" name="phone" id="phone"><span style="color: red" id="userPhoneInfo"></span>
            </div>
            <div class="form-group">
                <label>地址：</label>
                <a style="color: red">&nbsp;&nbsp;</a>
                <input class="form-control" th:value="${user.address}" name="address" id="address">
            </div>
            <div shiro:hasPermission="admin" class="form-group">
                <label >用户角色：</label>
                <!-- 列出所有的角色分类 -->
                <!-- <select name="userRole" id="userRole"></select> -->
                <a style="color: red">*</a>
                <select th:field="${user.userRole}" name="userRole" id="userRole">
                    <span th:each="role : ${roles}">
                         <option th:value="${role.id}" th:text="${role.roleName}"></option>
                    </span>
                </select>
            </div>

            <div class="providerAddBtn">
                <button type="submit" class="btn btn-primary" id="button_id"><a class="btn btn-default" >保存</a></button>
                <button><a type="button" class="btn btn-default" data-dismiss="modal" th:href="@{/toIndex}">返回</a></button>
            </div>
        </form>
    </div>

</div>
</section>
</body>
</html>